#include <iostream>
#include <queue>
#include <map>
using namespace std;

typedef struct node {
    int value;
    node *left, *right;
} *tree;

void level_order(tree t) {
    if(t == NULL) {
        return;
    }

    queue<node*> q;
    q.push(t);

    while(!q.empty()) {
        node *n = q.front();
        cout << n->value << " ";
        if(n->left != NULL) {
            q.push(n->left);
        }
        if(n->right != NULL) {
            q.push(n->right);
        }
        q.pop();
    }

    cout << endl;
}

int main() {
    int n;
    cin >> n;

    tree t;

    int x, y;
    map<int, node*> pair;
    map<int, bool> root;

    for(int i=0; i<n; ++i) {
        cin >> x >> y; // 输入父节点、子节点
        
        if(pair.find(x) == pair.end()) {
            pair[x] = new node();
            pair[x]->value = x;
        }
        if(pair.find(y) == pair.end()) {
            pair[y] = new node();
            pair[y]->value = y;
        }

        if(pair[x]->left == NULL) {
            pair[x]->left = pair[y];
        } else if (pair[x]->right == NULL) {
            pair[x]->right = pair[y];
        }

        if(root.find(x) == root.end()) {
            root[x] = true;
        }

        root[y] = false;
    } 

    for(auto i=root.begin(); i!=root.end(); ++i) {
        if(i->second == true) {
            t = pair[i->first];
            break;
        }
    }   

    level_order(t);

    return 0;
}